//
//  SYNoDataView.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/21.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "SYNoDataView.h"

@interface SYNoDataView()

@property (nonatomic , weak) UIImageView *imageView;

@property (nonatomic , weak) SYNoHeightedButton *saleButton;

@end

@implementation SYNoDataView


-(void)setIsCanSeeBuyButton:(BOOL)isCanSeeBuyButton
{
    _isCanSeeBuyButton = isCanSeeBuyButton;
    if (isCanSeeBuyButton) {
        self.saleButton.hidden = NO;
    }else{
        self.saleButton.hidden = YES;
    }
}
-(void)setImageString:(NSString *)imageString
{
    _imageString = imageString;
    self.imageView.image = [UIImage imageNamed:imageString];
}

-(void)setButtonTitle:(NSString *)buttonTitle
{
    _buttonTitle = buttonTitle;
    
    [self.saleButton setTitle:buttonTitle forState:UIControlStateNormal];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self imageView];
        
        [self saleButton];
    }
    return self;
}


+(instancetype)positionNoDataViewInitWithFrame:(CGRect)frame ImageString:(NSString *)imageString buttonTitle:(NSString *)buttonTitle IsCanSeeBuyButton:(BOOL)isCanSeeBuyButton
{
    SYNoDataView *dataView = [[self alloc] initWithFrame:frame];
    dataView.imageString = imageString;
    dataView.buttonTitle = buttonTitle;
    dataView.isCanSeeBuyButton = isCanSeeBuyButton;
    return dataView;
}

-(UIImageView *)imageView
{
    if (_imageView == nil) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        imageView.image = [UIImage imageNamed:self.imageString];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.centerX.equalTo(self);
        }];
        _imageView = imageView;
    }
    return _imageView;
}

-(SYNoHeightedButton *)saleButton
{
    if (_saleButton == nil) {
        SYNoHeightedButton *saleButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:saleButton];
        saleButton.backgroundColor = zhidainMainColor;
        [saleButton setTitle:@"发布策略" forState:UIControlStateNormal];
        [saleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        saleButton.titleLabel.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        saleButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        saleButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [saleButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(rate375(200)));
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(42)));
                make.top.equalTo(self.imageView.mas_bottom).offset(rateX812(38));
            }else{
                make.height.equalTo(@(rate750(42)));
                make.top.equalTo(self.imageView.mas_bottom).offset(rate750(38));
            }
            make.centerX.equalTo(self);
        }];
        saleButton.layer.cornerRadius = 3.0;
        saleButton.layer.masksToBounds = YES;
        saleButton.hidden = YES;
        [saleButton addTarget:self action:@selector(saleButtonClick:) forControlEvents:UIControlEventTouchDown];
        _saleButton = saleButton;
    }
    return _saleButton;
}
-(void)saleButtonClick:(SYNoHeightedButton *)button
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(noDataView:didClickSaleButton:)]) {
        [self.delegate noDataView:self didClickSaleButton:button];
    }
}


@end
